package cn.tedu.fresheveryday.mapper;

import cn.tedu.fresheveryday.pojo.entity.UserReceiveInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserReceiveInfoMapper {
    /**
     * 通过用户id查询收货信息
     * @param userId
     * @return
     */
    @Select(
            "select id, name, address, phone from user_receive_info " +
            "where user_id = #{userId}"
    )
    List<UserReceiveInfo> selectByUserId(String userId);

    /**
     * 通过id修改收货信息
     * @param rec
     */
    @Update(
            "update user_receive_info " +
            "set name = #{name}, address = #{address}, phone = #{phone} " +
            "where id = #{id}"
    )
    void updateById(UserReceiveInfo rec);

    /**
     * 添加收货信息
     * @param rec
     */
    @Insert(
            "insert into user_receive_info (" +
                    "id, name, address, user_id" +
            ") values (" +
                    "#{id}, #{name}, #{address}, #{userId}" +
            ")"
    )
    void insert(UserReceiveInfo rec);

    /**
     * 通过id查询收货信息
     * @param distId
     * @return
     */
    @Select("select id, name, address, phone from user_receive_info where id = #{distId}")
    UserReceiveInfo selectById(String distId);
}